import java.util.ArrayList;
import java.util.Arrays;

import static java.lang.System.err;
import static java.lang.System.out;

public abstract class IterDeep extends ComputerPlayer {
    public IterDeep(boolean isBlack, Eval evaluator, int maxDepth) {
        super(isBlack, evaluator, maxDepth);
    }


    public abstract Board findMove(Board board, ArrayList<Board> moves,
                                   int depth);


    @Override
    public Action getMove(Board board, int moveNbr) {

        long startTime = System.currentTimeMillis();

        assert board.blackToMove == isBlack;


        ArrayList<Board> moves = board.generateMoves();
        Board bestMove = null;

        // Iterative deepening
        for( int depth = 2; depth <= searchDepth; depth+=2 ) {
            bestMove = findMove(board, moves, depth);
        }


        // Print the move
        int[] myMove;
        if (bestMove != null) {
            myMove = movePathFromBoards(board, bestMove);
            out.print("My move is " + moveNbr + ": " + myMove[0]);
            for (int i = 1; i < myMove.length; i++) {
                out.print(" - " + myMove[i]);
            }
            out.println();
        } else {
            out.println(color + " couldn't find any available moves.");
            myMove = new int[0];
        }


        // Add time spent and print the time
        long endTime = System.currentTimeMillis();
        long thisMove = endTime - startTime;
        spentTime += thisMove;
        float thisMoveTime = thisMove / 1000.0F;
        float totalTime = spentTime / 1000.0F;
        out.printf("This move took: %.2f s.\n", thisMoveTime);
        out.printf("Total spent time: %.2f s.\n", totalTime);


        return new Action(myMove, spentTime);
    }
}
